//
//  BKMeViewController.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/5/25.
//  Copyright (c) 2015年 报考大学. All rights reserved.
//

#import "BKMeViewController.h"
#import "BKSettingViewController.h"
#import "BKMessageViewController.h"
#import "BKMeViewModel.h"
#import <UIImageView+AFNetworking.h>
#import "BKArchiveViewController.h"
#import "LoginViewController.h"
#import "BKXinLiHuaViewController.h"
#define DATA @[@"我的消息",@"我的梦想大学存档",@"设置"]
@interface BKMeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIImageView *photoImageView;


@end

@implementation BKMeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UITabBarController *tabBarViewController = (UITabBarController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
    [tabBarViewController.tabBar setBarTintColor:[UIColor colorWithRed:0.467 green:0.718 blue:0.863 alpha:1.000]];
    
  
}

- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    UITabBarController *tabBarViewController = (UITabBarController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
    
    if ([tabBarViewController isKindOfClass:[UITabBarController class]]) {
        [tabBarViewController.tabBar setBarTintColor:[UIColor colorWithRed:0.467 green:0.718 blue:0.863 alpha:1.000]];
    }
    
    
    __weak BKMeViewController *weakSelf = self;
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    if ([userDefaults objectForKey:@"Cookie"] !=nil) {
        [BKMeViewModel avardaWithSuccess:^(NSString *message) {
            [weakSelf.photoImageView setImageWithURL:[NSURL URLWithString:message]];
            
        } failure:^(NSString *message) {
            
        }];
        
        
    }

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark tableView 
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *reuseIndentify = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIndentify];
    if (!cell) {
        [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseIndentify];
        cell = [tableView dequeueReusableCellWithIdentifier:reuseIndentify];
        
    }
    tableView.separatorColor = [UIColor colorWithRed:0.196 green:0.600 blue:0.878 alpha:1.000];
    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
    cell.selectedBackgroundView .backgroundColor = [UIColor colorWithRed:0.455 green:0.702 blue:0.843 alpha:1.000];
    cell.textLabel.text = DATA[indexPath.row];
    return cell;

}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section{

    return  [DATA count];
}

- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section{
    return 20;
}

- (UIView *)tableView:(UITableView *)tableView
viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 20)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    if ([userDefaults objectForKey:@"Cookie"] !=nil) {
    
        switch (indexPath.row) {
            case 0:{
                
                BKMessageViewController *messageViewController = [[BKMessageViewController alloc] initWithNibName:NSStringFromClass([BKMessageViewController class]) bundle:nil];
                [self.navigationController pushViewController:messageViewController animated:YES];
                break;
                
            }
            case 1:{
            
                BKArchiveViewController *archiveVC = [[BKArchiveViewController alloc] initWithNibName:NSStringFromClass([BKArchiveViewController class]) bundle:nil];
                
                
                [self.navigationController pushViewController:archiveVC animated:YES];
                break;
            }
                
//            case 9:{
//            
//                BKXinLiHuaViewController *xinlihua = [[BKXinLiHuaViewController alloc] initWithNibName:NSStringFromClass([BKXinLiHuaViewController class]) bundle:nil];
//                [self.navigationController pushViewController:xinlihua animated:YES];
//                break;
//        
//            }
            case 2:{
                BKSettingViewController *viewController = [[BKSettingViewController alloc] initWithNibName:NSStringFromClass([BKSettingViewController class]) bundle:nil];
                [self.navigationController pushViewController:viewController animated:YES];
                break;
            }
                
                
                
            default:
                break;
        }

    
    }else{
    
    
        LoginViewController *login = [[LoginViewController alloc] initWithNibName:NSStringFromClass([LoginViewController class]) bundle:nil];
        [self presentViewController:login animated:YES completion:nil];

    }

    
   
    
}
@end
